let arr = [5,4,[3,1,[5,6,[9,8]]]];
function flat(arr)
{
    let newArr = arr.reduce((prev,next,index)=>
    {
          return  prev.concat(next instanceof Array ? flat(next):next);
     
    },[])
    return newArr;
}
console.log(flat(arr));
let  arr1 = flat(arr);
let  num =0;
arr1.forEach(x =>
    {
        num +=x;
    })
console.log("和是"+num);